from django.contrib.auth.models import Permission, ContentType
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from meiduo_admin.serialziers.permission import PermissionSerializer, ContentTypeSerializer
from meiduo_admin.utils.page import PageNum


class PermissionView(ModelViewSet):
    serializer_class = PermissionSerializer
    queryset = Permission.objects.all()
    pagination_class = PageNum

    # 对于权限类型操作
    def content_types(self, request):
        """
        获取权限类型
        :param request:
        :return:
        """
        # 获取权限类型的所有数据
        data = ContentType.objects.all()

        ser = ContentTypeSerializer(data, many=True)
        return Response(ser.data)